package MyServlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Candidate;
import model.Comment;
import service.ServiceException;
import ServletService.Service;

/**
 * Servlet implementation class CrudComment
 */
public class CrudComment extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private String option;
	private Service service;
	private Comment comment;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public CrudComment() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		option = request.getParameter("option");

		switch (option) {
		case "add":
			Service.getCommentService().insertComment(comment);
			break;
		case "update": {
			Service.getCommentService().updateComment(comment);

			break;
		}
		case "delete": {
			Service.getCommentService().deleteComment(comment);

			break;
		}
		case "getAll": {
			Service.getCommentService().getAll();

			break;
		}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
